class Solution {
    vector<vector<int>> ret;
    vector<int> path;
    int sz;
public:
    vector<vector<int>> subsets(vector<int>& nums) {
        sz= nums.size();
        dfs2(nums, 0);
        return ret;
    }
    void dfs2(vector<int>& nums, int pos)
    {
        ret.push_back(path);
        for(int i = pos; i < sz; ++i)
        {
            path.push_back(nums[i]);
            dfs(nums, i + 1);
            path.pop_back();
        }
    }

    void dfs(vector<int>& nums, int i)
    {
        if(i == sz)
        {
            ret.push_back(path);
            return;
        }
        path.push_back(nums[i]); // 选
        dfs(nums, i + 1);
        path.pop_back(); // 回溯

        dfs(nums, i + 1); // 不选
    }
};